var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 工作日程 - 其他
 */
module.exports = Waterline.Collection.extend({
    identity: 'workdiary',
    tableName: 'tb_workdiary',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function() {
                return uuid.v4();
            }
        },
        title: {
            type: 'string',
            required: true,
            columnName: 'title'
        },
        startTime: {
            type: 'datetime',
            required: true,
            before: function () {
                return this.finishTime;
            },
            columnName: 'starttime'
        },
        finishTime: {
            type: 'datetime',
            required: true,
            after: function () {
                return this.startTime;
            },
            columnName: 'finishtime'
        },
        content: {
            type: 'string',
            columnName: 'content'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        toJSON: function() {
            var obj = this.toObject();
            obj.createdAt=moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt=moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');
            obj.startTime=moment(obj.startTime).format('YYYY/MM/DD hh:mm');
            obj.finishTime=moment(obj.finishTime).format('YYYY/MM/DD hh:mm');
            return obj;
        }

    }
});
